#pragma once
/*
v1.0.0 impletement the base funtion
v2.0.0	add ClearBuffer
		remove Init
*/
#include<windows.h>
#include<string>

//uncomment to use header only
#define SHARED_MEMORY_HEADER_ONLY
#define ALGORITHM_SHARED_MEMORY_VERSION 2.0.0

namespace vrts
{
	class SharedMemory
	{
	public:
		SharedMemory(std::string sharedName, size_t memorySize, std::string fileName = "");
		~SharedMemory();

		unsigned char* GetBaseAddr();
		size_t GetMemorySize();
		bool WriteMemory(size_t offset,void* data, size_t length = 0);
		bool ReadMemory( size_t offset,void* data, size_t length = 0);
		void ClearMemory(size_t offset, size_t length = 0);
	private:
		bool CreateMMF();

		// share memery
		std::string m_sharedName;
		std::string m_fileName;
		HANDLE m_hMapFile{ nullptr};
		HANDLE m_hFile{ nullptr };
		size_t m_memorySize{ 0 };
		unsigned char *m_baseAddr{ nullptr };
	};


}//namespace vrts

#if defined(SHARED_MEMORY_HEADER_ONLY)&& !defined(SOURCE_FILE)
#define SOURCE_FILE "sharedMemory.cpp"
#include SOURCE_FILE
#endif